<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css">
  <script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script>
  <script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<form action="{:url('/groupList')}">
  <input type="text" name="keywords" {if $keywords==''} value="" {else} value="{$keywords}" {/if}>
  <button type="submit">搜索</button>
</form>
<button id="delAll">批量删除</button>
<a href="{:url('/allExport')}"><button>全部导出</button></a>
<a href="{:url('/someExport')}"><button>部分导出</button></a>
<table class="table">
  <thead>
  <tr>
    <th><input type="checkbox"></th>
    <th>id</th>
    <th>组名</th>
    <th>状态</th>
    <th>操作</th>
  </tr>
  </thead>
  <tbody>
  {foreach $data as $val}
  <tr>
    <td><input type="checkbox" {if $val.state == 1} disabled {/if}></td>
    <td>{$val.id}</td>
    <td>{$val.group_name}</td>
    <td>{if $val.state==1}正常{else}隐藏{/if}</td>
    <td><a href="{:url('/updateShow',['id'=>$val.id])}"><button type="button" class="btn btn-warning">修改</button></a><button type="button" class="btn btn-danger delGroup">删除</button></td>
  </tr>
  {/foreach}
  </tbody>
</table>
{$data|raw}
</body>
</html>
<script>
  $('#delAll').click(function (){
    var id=[]
    $('input:checked').each(function (){
      id.push($(this).parents('tr').children().eq(1).html())
    })
    $.ajax({
      url:'delGroupAll',
      dataType:'json',
      type:'get',
      data:{id:id},
      success:function (e){
        if(e.code==200){
          $('input:checked').each(function (){
            $(this).parents('tr').remove()
          })
        }
      }
    })
  })
  $('.delGroup').click(function (){
    var id=$(this).parents('tr').children().eq(1).html()
    var _this=$(this)
    if($(this).parents('tr').children().eq(3).html()!='正常'){
      if(confirm('你确定删除吗？')){
        $.ajax({
          url:'delGroup',
          dataType:'json',
          type:'get',
          data:{id:id},
          success:function (e){
            if(e.code==200){
              _this.parents('tr').remove()
              alert('删除成功')
            }else {
              alert('删除失败')
            }
          }
        })
      }
    }else{
      alert('这是正常的组,不可删除')
    }

  })
</script>